#5-45
products=[("milk",5),("egg",20),("blanana",10),("cup",10)]
shopping_list=[]
money=float(input("shopping money:"))
while True:
    print("*"*30)
    print("object list:")
    for index,product in enumerate(products):
        print(f"{index+1}.object:{product[0]},price:{product[1]}")
    print("*"*30)
    option=input("buy object(exit q):")
    if option.isdigit():
        option=int(option)
        if 0<=option-1<len(products):
            option_product=products[option-1]
            if option_product[1]<=money:
                shopping_list.append(option_product)
                money-=option_product[1]
                print("success")
            else:
                print(f"no money,residue:{money}")
        else:
            print("no live")
    elif option=="q":
        print("-"*10,"buy object list","-"*10)
        for item in shopping_list:
            print(f"have buied object:{item[0]},price:{item[1]}")
        print("my residue",money)
        break
    else:
        print("illegality")
    

#5-44
food_tuple = ("rice","pumpkin porridge","roast duck")
for item in food_tuple:
    print("element:",item)

#5-43
tuple01 = tuple()
tuple02 = tuple("husong")
tuple03 = tuple([1,2,3,4,5])
tuple04 = tuple(range(1,5,2))
print("tuple01:",tuple01)
print("tuple02:",tuple02)
print("tuple03:",tuple03)
print("tuple04:",tuple04)

#5-42
run_list = ["0minute","20minutes","40minutes","60minutes"]
swim_list = ["0meter","200meters","400meters","600meters"]
calories_list = []
for i in range(len(run_list)):
    for j in range(len(swim_list)):
        calories_list.append(i*200+j*100)
print("heat:",calories_list)
print(f"exercise planconsumes the most{max(calories_list)}heat,planconsumes the minimal{min(calories_list)}heat")

#5-41
run_list = ["0minute","20minutes","40minutes","60minutes"]
swim_list = ["0meter","200meters","400meters","600meters"]
for index,run in enumerate(run_list):
    print(f"{index+1}、{run}")
run_opt = int(input("choose run_list:"))
for index,swim in enumerate(swim_list):
    print(f"{index+1}、{swim}")
swim_opt = int(input("choose swim_list:"))
print(f"sport todolist:run{run_list[run_opt-1]},swim{swim_list[swim_opt-1]}")

#5-40
origin_list = [1,4,5,12,32,31,54]
even_list = [item for item in origin_list if item % 2 == 0]
print(even_list)

#5-39
origin_list = [1,4,5,12,32,31,54]
even_list = []
for item in origin_list:
    if item % 2 == 0:
        even_list.append(item)
print(even_list)

#5-38
square_list = []
for item in range(1,11):
    square_list.append(item ** 2)
print(square_list)


#5-37
person_hobbies = ["swim","run","sing"]
friend_hobbies = person_hobbies
person_hobbies.append("climb")
friend_hobbies.append("grow flowers")
print("person_hobbies:",person_hobbies)
print("friend_hobbies:",friend_hobbies)

#5-36
person_hobbies = ["swim","run","sing"]
friend_hobbies = person_hobbies
print(friend_hobbies)

#5-35
person_hobbies = ["swim","run","sing"]
friend_hobbies = person_hobbies[:]
person_hobbies.append("climb")
friend_hobbies.append("grow flowers")
print("person_hobbies:",person_hobbies)
print("friend_hobbies:",friend_hobbies)

#5-34
person_hobbies = ["swim","run","sing"]
friend_hobbies = person_hobbies[:]
print("friends' hobbies",friend_hobbies)

#5-33
age_list = [17,16,18,19,16,18]
sort_list = sorted(age_list,reverse=True)
print("sort:",sort_list)

#5-32
age_list = [17,16,18,19,16,18]
sort_list = sorted(age_list)
print("sort:",sort_list)
print("original:",age_list)

#5-31
poem = "abcd,efgh"
poem_list = list(poem)
print("poem turn list is:",poem_list)
poem_list.reverse()
print("list reverse is:",poem_list)
poem_reverse = "".join(poem_list)
print("use join() let list merge char string",poem_reverse)

#5-30
age_list = [17,16,18,19,16,18]
age_list.sort(reverse=True)
print(age_list)

#5-29
age_list = [17,16,18,19,16,18]
age_list.sort()
print(age_list)

#5-28
list01 = [1,2,3,4,5,6,7,8,9,10]
del list01[2]
print(list01)
del list01[1:3]
print(list01)
del list01[:]
print(list01)

#5-27
list01 = [1,2,3,4]
list01.remove(2)
print(list01)

#5-26
list01 = [1,2,3,4]
element = list01.pop()
print(f"del{element},list01 turn {list01}")
element = list01.pop(0)
print(f"del{element},list01 turn {list01}")

#5-25
list01 = [1,2,3,4]
list01[1:3] = [9,10]
print(list01)

#5-24
list01 = [1,2,3,4]
list01[1] = 5
print(list01)

#5-23
list01 = [1,2,3,4]
list01.insert(1,"insert")
print(list01)

#5-22
list01 = [1,2,3,4]
list01.extend([5,6,7])
print(list01)

#5-21
list01 = [1,2,3,4]
list01.append(5)
print(list01)

#5-20
food_list = ["apple","banana","orange","mango"]
for index,item in enumerate(food_list):
    print(f"index {index} is {item}")

#5-19
food_list = ["apple","banana","orange","mango"]
for i in range(len(food_list)):
    print(f"index {i} is {food_list[i]}")

#5-18
food_list = ["apple","banana","orange","mango"]
for item in food_list:
    print("traversal:",item)

#5-17
list02 = list("husong")
print("list02:",list02)
sname = "".join(list02)
print("list02 char string:",sname)

#5-16
list01 = list()
list02 = list("husong")
list03 = list((1,2,3,4,5))
list04 = list(range(1,5,2))
print("list01:",list01)
print("list02:",list02)
print("list03:",list03)
print("list04:",list04)



#5-15
list01 = ["hello",123,"Python",123]
print("count 123 times:",list01.count(123))

#5-14
list01 = ["hello",123,"Python",123]
print("first 123 index:",list01.index(123))

#5-13
sname="Python"
print("MIN:",min(sname))
tuple01=("Python","Hello","Tuple")
print("MIN:",min(tuple01))

#5-12
list01 = ["hello","happy","python"]
print("max:",max(list01))

#5-11
print('"hello">"happy" result:',"hello">"happy")

#5-10
print("'a'Unicode is:",ord("a"))
print("Unicode is 97 chr:",chr(97))


#5-9
list01 = [1,7,8,4,4,5,6]
print("MAX:",max(list01))

#5-8
sname="Python"
print("long:",len(sname))
list01 = ["Python","C++","JAVA","GO"]
print("long:",len(list01))
tuple01 = ("Python","C++","JAVA","GO")
print("long:",len(tuple01))

#5-7
tuple01 = ("hs","edu")
if "hs" not in tuple01:
    print("'hs'not in tuple01")
else:
    print("'hs' in tuple01")

#5-6
list01 = [1,2,3,4,5]
if 3 in list01:
    print("3 in list01")
else:
    print("3 not in list01")

#5-5
print("Python"*5)
print(["Python"]*5)
print(("Python",1)*5)


#5-4
list01 = ["a","b","c"]
sname = "m"
print(list01+sname)


#5-3
list01 = ["a","b","c"]
list02 = ["d","e"]
print(list01+list02)

#5-2
list01 = [1,2,"Python","hs"]
print("list01[1:3]:",list01[1:3])
print("list01[:3]:",list01[:3])
print("list01[::2]:",list01[::2])

#5-1
list01 = [1,2,"Python","hs"]
print("list01[3]:",list01[3])
print("list01[-1]:",list01[-1])